import "./header_logined.html"


import { Template } from 'meteor/templating';
import { Message } from '../../components/message/message.js';


Template.normal_header_logined.onCreated(function(){
	let self = this;
  self.roles = new ReactiveVar([]);
  self.autorun(function(){
    if (Session.get("roles")!=undefined) {
      self.roles.set(Session.get("roles"));
    }else{
      self.roles.set([]);
    }
  });
});

Template.normal_header_logined.onRendered(function(){
  $('.ui.dropdown')
    .dropdown()
  ;
});

Template.normal_header_logined.helpers({
	isMember(){
    let roles = Template.instance().roles.get();
    let isM = false;
    for (var i = 0; i < roles.length; i++) {
      let role_name = roles[i].name;
      if (role_name == "万车汇会员") {
        isM = true;
      }
    }
    return isM;
  },
  isLawadmin(){
    let roles = Template.instance().roles.get();
    let isM = false;
    for (var i = 0; i < roles.length; i++) {
      let role_name = roles[i].name;
      if (role_name == "法律文件管理员") {
        isM = true;
      }
    }
    return isM;
  },
	username(){
		return Meteor.user().username;
	}
});

Template.normal_header_logined.events({
	'click .link_member_abilities'(){
		event.preventDefault();
    event.stopPropagation();
		FlowRouter.go('/member_abilities');
	},
	'click .link_logout'(){
		event.preventDefault();
    event.stopPropagation();
		Meteor.logout();
		FlowRouter.go('/');
		Message.sendSuccess("您已安全退出～");
	},
	'click .link_help'(){
		event.preventDefault();
    event.stopPropagation();

		FlowRouter.go('App.help');

	},
	'click .link_law_admin'(){
		event.preventDefault();
    event.stopPropagation();

		FlowRouter.go('/admin/law_docs/');

	}
});
